/*
 * =====================================================================================
 *
 *       Filename:  avlTree.h
 *
 *    Description:  
 *
 *        Version:  0.1
 *        Created:  2017/02/12 15:38:56
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Brook L. (), Brook_L@163.com
 *   Organization:  
 *
 * =====================================================================================
 */

#ifndef _AVLTREE_H_
#define _AVLTREE_H_

// <user: include AVL tree node content file, must be modified by user>
#include "../App/CmdSet/cmd.h"

typedef struct avlNode {
    struct avlNode *left;                       // left node
    struct avlNode *right;                      // right node
    int height;                                 // height of the node
    AvlNodeContent content;                     // content of the node
} AvlNode;

typedef struct avlTree {
    AvlNode *root;                              // root node of AVL tree
    int (*compare)(AvlNodeContent *content1,
            AvlNodeContent *content2);          // compare two nodes' content, must be implemented by user
    void (*insertMatchProcess)(AvlNodeContent
            *content);                          // process when a node already exists during inserting,
                                                // could be implemented by user
    void (*travProcess)(AvlNodeContent
            *content);                          // process when traverse the AVL tree, could be implemented
                                                // by user
} AvlTree;

void avlInit (AvlTree *avlTree, int (*compare)(AvlNodeContent *, AvlNodeContent *),
        void (*insertMatchProcess)(AvlNodeContent *), void (*travProcess)(AvlNodeContent *));
AvlNode *avlInsert(AvlTree *avlTree, AvlNode *node, AvlNodeContent *content);
AvlNode *avlFind(AvlTree *avlTree, AvlNode *node, AvlNodeContent *content);
void avlTrav(AvlTree *avlTree, AvlNode *node);

#endif /* #ifndef _AVLTREE_H_ */
